package com.mulanweb.api.module.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.upload.UploadFile;
import com.mulanweb.api.module.model.Photo;
import com.mulanweb.db.common.Constant;
import com.mulanweb.db.common.RandomStringGenerator;
import com.mulanweb.utils.StringFormatterUtil;
import com.mulanweb.validator.annotation.ValidateFile;
import com.mulanweb.validator.annotation.ValidateForm;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.util.*;

/**
 * Created by Administrator on 2016/9/18.
 */
@ValidateFile
public class PhotoController extends BaseController {
    /**
     * 得到ticket 的照片地址
     */
    @ValidateForm
    public void getPhotos() {
        Long targetId = getParaToLong("targetId");
        Long typeId = getParaToLong("typeId");
        Integer typeId2 = null;
        if (typeId == 13) {
            typeId2 = 14;
        }else if(typeId == 17){
            typeId2 = 18;
        } else {
            typeId2 = 16;
        }
        List<Photo> photos = Photo.dao.find("select * from photo where (type_id = ? OR type_id = ?) AND target_id = ? ORDER BY type_id DESC", typeId, typeId2, targetId);
        List<String> photoPath = new ArrayList<String>(photos.size());
        for (int i = 0; i < photos.size(); i++) {
            photoPath.add(i, photos.get(i).getPath());
        }
        returnSuccessJson(photoPath);
    }

}
